package com.eflow.autoconfig;

import com.eflow.engine.listener.GlobalTaskListener;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.common.engine.impl.AbstractEngineConfiguration;
import org.flowable.common.engine.impl.EngineConfigurator;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * @author hui se
 * @description
 * @create 2021-04-29 18:13
 **/
public class FlowableConfig  implements EngineConfigurator {
    @Autowired
    private ProcessEngineConfigurationImpl processEngineConfiguration;
    @Autowired
    private GlobalTaskListener globalTaskListener;

    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        FlowableEventDispatcher dispatcher = processEngineConfiguration.getEventDispatcher();
        //任务创建全局监听
//        dispatcher.addEventListener(globalTaskListener, FlowableEngineEventType.TASK_CREATED);
//        dispatcher.addEventListener(globalTaskListener, FlowableEngineEventType.TASK_ASSIGNED);
//        dispatcher.addEventListener(globalTaskListener, FlowableEngineEventType.TASK_COMPLETED);
    }

    @Override
    public void beforeInit(AbstractEngineConfiguration engineConfiguration) {

    }

    @Override
    public void configure(AbstractEngineConfiguration engineConfiguration) {
        FlowableEventDispatcher dispatcher = processEngineConfiguration.getEventDispatcher();
    }

    @Override
    public int getPriority() {
        return 0;
    }
}
